
package Ajedrez;

import Main.BotonCasilla;

class Peon extends Pieza {

    protected int iniX, iniY, finX, finY;


    public Peon() {
    }

    public Peon(BotonCasilla[][] figura, int iniX, int iniY, int finX, int finY) {
        this.iniX = iniX;
        this.iniY = iniY;
        this.finX = finX;
        this.finY = finY;
        int i, f;
        
        int pos[][] = { {1, 0},
                        {1, -1},
                        {1, 1},};

        int Npos[][] = {{-1, 0},
                        {-1, -1},
                        {-1, 1},};

        String[][] jugadorB = {{"blanco", "blanco", "blanco", "blanco", "blanco", "blanco"},
            {"torre", "caballo", "alfil", "reina", "rey", "peon"},
            {"torre", "caballo", "alfil", "reina", "rey", "peon"},};

        String[][] jugadorN = {{"blanco", "blanco", "blanco", "blanco", "blanco", "blanco"},
            {"Ntorre", "Ncaballo", "Nalfil", "Nreina", "Nrey", "Npeon"},
            {"Ntorre", "Ncaballo", "Nalfil", "Nreina", "Nrey", "Npeon"},};
        super.corrept = false;


        if (figura[this.iniX][this.iniY].getPieza().equalsIgnoreCase("Npeon")) {
            //Movimiento doble al principio
            if (iniX == 1 && finX == 3 && finY == iniY) {
                super.corrept = true;
            }
            else {
                for (int x = 0; x < 3; x++) {
                    i = this.iniX + pos[x][0];
                    f = this.iniY + pos[x][1];
                    
                    if ((i > -1) && (i < 8) && (f > -1) && (f < 8)) {
                        if ((i == this.finX) && (f == this.finY)) {
                            for (int g = 0; g < 6; g++) {
                                if (figura[this.finX][this.finY].getPieza().equalsIgnoreCase(jugadorB[x][g])) {
                                    super.corrept = true;
                                }
                            }
                        }
                    }
                }
            }
        }

        if (figura[this.iniX][this.iniY].getPieza().equalsIgnoreCase("peon")) {
            if (iniX == 6 && finX == 4 && finY == iniY) {
                super.corrept = true;
            }
            else {
                for (int xx = 0; xx < 3; xx++) {
                    i = this.iniX + Npos[xx][0];
                    f = this.iniY + Npos[xx][1];

                    if ((i > -1) && (i < 8) && (f > -1) && (f < 8)) {
                        if ((i == this.finX) && (f == this.finY)) {
                            for (int gg = 0; gg < 6; gg++) {
                                if (figura[this.finX][this.finY].getPieza().equalsIgnoreCase(jugadorN[xx][gg])) {
                                    super.corrept = true;
                                }
                            }
                        }
                    }
                }
            }
        }
    }    
}
